"use strict";
cc._RF.push(module, '426c1XbOLxK3pjSbXk37ngp', 'NativeAd_Oppo_Single');
// scripts/NativeAd_Oppo_Single.js

"use strict";

var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
  value: !0
});

var o = e("NativeAdBase"),
    i = cc._decorator,
    a = i.ccclass,
    r = i.property,
    s = function (e) {
  __extends(t, e);

  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.delay = .5;
    t.posID = "";
    t.adNode = null;
    t.title = null;
    t.desc = null;
    t.iconSprite = null;
    t.mainSprite = null;
    t.closeBtn = null;
    t.extentBtns = [];
    t.nativeAd = null;
    t.nativeDataArr = [];
    t.curNativeData = null;
    return t;
  }

  t.prototype.start = function () {
    var e = this;

    if (cc.sys.platform == cc.sys.OPPO_GAME) {
      this.adNode && (this.adNode.active = !1);

      for (var t = 0; t < this.extentBtns.length; t++) {
        this.extentBtns[t].active = !1;
      }

      cc.sys.platform == cc.sys.OPPO_GAME && setTimeout(function () {
        e.init();
      }, 1e3 * this.delay);
    }
  };

  t.prototype.init = function () {
    this.nativeAd = qg.createNativeAd({
      posId: this.posID
    });
    var e = this;
    setTimeout(function () {
      e.nativeAd.load();
    }, 200);
    setInterval(function () {
      e.nativeDataArr.length < 5 ? e.nativeAd.load() : console.log("NativeUIAd Has ", e.nativeDataArr.length);
    }, 5e3);
    this.nativeAd.onLoad(function (t) {
      console.log("NativeUIAd: ", e.posID, JSON.stringify(t.adList));
      t.adList.forEach(function (t) {
        e.nativeDataArr.push(t);
      });
    });
    this.nativeAd.onError(function (t) {
      t && console.log("NativeUIAd: ", e.posID, ", OnError", JSON.stringify(t));
    });
  };

  t.prototype.canShow = function () {
    return !(SDK.Mgr.Inst.gameTime < SDK.Mgr.Inst.adProtectTime) && this.nativeDataArr.length > 0;
  };

  t.prototype.show = function (e) {
    void 0 === e && (e = !0);
    if (cc.sys.platform == cc.sys.OPPO_GAME) if (this.canShow()) {
      this.adNode && (this.adNode.active = !0);
      this.closeBtn && (this.closeBtn.active = !0);

      for (o = 0; o < this.extentBtns.length; o++) {
        this.extentBtns[o].active = !0;
      }

      this.curNativeData = this.nativeDataArr.pop();
      this.title && (this.title.string = this.curNativeData.title);
      this.desc && (this.desc.string = this.curNativeData.desc);
      this.iconSprite && (this.curNativeData.icon ? SDK.Util.Helper.loadImage(this.iconSprite, this.curNativeData.icon) : this.curNativeData.imgUrlList && this.curNativeData.imgUrlList.length > 0 && SDK.Util.Helper.loadImage(this.iconSprite, this.curNativeData.imgUrlList[0]));
      this.mainSprite && (this.curNativeData.imgUrlList && this.curNativeData.imgUrlList.length > 0 ? SDK.Util.Helper.loadImage(this.mainSprite, this.curNativeData.imgUrlList[0]) : this.curNativeData.icon && SDK.Util.Helper.loadImage(this.mainSprite, this.curNativeData.icon));
      this.nativeAd.reportAdShow({
        adId: this.curNativeData.adId
      });
    } else {
      if (e) {
        var t = this,
            n = function n() {
          if (t.canShow()) {
            t.unschedule(n);
            t.show();
          }
        };

        this.schedule(n, .1, 30);
      }

      for (var o = 0; o < this.extentBtns.length; o++) {
        this.extentBtns[o].active = !1;
      }

      this.closeBtn && (this.closeBtn.active = !1);
    }
  };

  t.prototype.click = function () {
    this.nativeAd && this.curNativeData && this.nativeAd.reportAdClick({
      adId: this.curNativeData.adId
    });
  };

  t.prototype.close = function () {
    this.adNode && (this.adNode.active = !1);

    for (var e = 0; e < this.extentBtns.length; e++) {
      this.extentBtns[e].active = !1;
    }
  };

  __decorate([r(cc.Float)], t.prototype, "delay", void 0);

  __decorate([r(cc.String)], t.prototype, "posID", void 0);

  __decorate([r(cc.Node)], t.prototype, "adNode", void 0);

  __decorate([r(cc.Label)], t.prototype, "title", void 0);

  __decorate([r(cc.Label)], t.prototype, "desc", void 0);

  __decorate([r(cc.Sprite)], t.prototype, "iconSprite", void 0);

  __decorate([r(cc.Sprite)], t.prototype, "mainSprite", void 0);

  __decorate([r(cc.Node)], t.prototype, "closeBtn", void 0);

  __decorate([r([cc.Node])], t.prototype, "extentBtns", void 0);

  return __decorate([a], t);
}(o["default"]);

n["default"] = s;

cc._RF.pop();